/*
 * @(#)GraphElement.java 1.0 14/11/13
 * 
 * Clase Compartida
 * PROP Grupo 13 Cluster 3
 */
package dominio;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Rafael Simon Garcia on 11/14/13.
 */
public class GraphElement extends Object{
    public Integer id;
    public String name;
    public String description;

    public HashMap<Integer, Integer> costs;


    //Constructors

    //Empty Constructor
    public GraphElement(){}

    //Constructor that receives the id
    public GraphElement(int i){ this.id = i; }
    //Constructor that receives the id and name
    public GraphElement(int i, String n){
        this.id = i;
        this.name = n;
    }
    //Constructor that receives the id, name and description
    public GraphElement(int i, String n, String d){
        this.id = i;
        this.name = n;
        this.description = d;
    }

    //Constructor that receives the id, name, description and costs
    public GraphElement(int i, String n, String d, ArrayList<Cost> costsList){
        this.id = i;
        this.name = n;
        this.description = d;
        this.costs = new HashMap<>();
        SetGraphElementCostsList(costsList);
    }

    //Protected function that sets the HashMap cost from an ArrayList
    protected void SetGraphElementCostsList(ArrayList<Cost> costsList){
        if(this.costs == null) this.costs = new HashMap<>();
        for(Cost c: costsList)
            this.costs.put(c.id, c.cost);
    }

    //Setter for name attribute
    public void SetName (String newName){ this.name = newName; }
    //Setter for description attribute
    public void SetDescription (String newDescription){ this.description = newDescription; }

    //Gets the edge cost to another GraphElement, the key parameter is the id of the other element.
    public int GetCostTo(int key){
        return !this.costs.containsKey(key) ? -1 : this.costs.get(key);
    }
}
